package com.atguigu.patterns.factory.absfactory;

import com.atguigu.patterns.factory.result.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Client {
    public static void main(String[] args) {
        Client client = new Client();
        String type = client.getType();

        // 根据 type 确定工厂的选择
        Pizza pizza = new LDFactory().createCheesePizza();
        Pizza pizza1 = new LDFactory().createPepperPizza();
        Pizza pizza2 = new BJFactory().createCheesePizza();
        Pizza pizza3 = new BJFactory().createPepperPizza();

        if (pizza != null) { // 订购ok
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } else {
            System.out.println("订购失败");
        }
    }

    private String getType() {
        try {
            BufferedReader string = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = string.readLine();
            return str;
        } catch (IOException e) {
            return "";
        }
    }
}
